import axios from 'axios'
import { ElMessage } from 'element-plus'
const defaultConfig = {
  baseURL: import.meta.env.VITE_BASE,
}

const instance = axios.create(Object.assign({}, defaultConfig))

instance.interceptors.request.use(
  function (config) {
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)
instance.interceptors.response.use(
  function (response) {
    const res = response.data
    if (res.code === 'S0001') {
      return res.bizContent
    } else {
      ElMessage({
        message: res.message,
        type: 'error',
      })
      return Promise.reject(res)
    }
  },
  function (error) {
    return Promise.reject(error)
  }
)
export default instance
